package com.code_g.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ConnectUtils {

    public static Connection connection;


    public static Connection getConnection() throws IOException, TimeoutException {
        //创建连接工厂
        ConnectionFactory connectionFactory = new ConnectionFactory();
        //设置参数
        //主机
        connectionFactory.setHost("localhost");
        //端口
        connectionFactory.setPort(5672);
        //虚拟主机
        connectionFactory.setVirtualHost("/codeg");
        //用户名
        connectionFactory.setUsername("guest");
        //密码
        connectionFactory.setPassword("guest");

        //创建连接
        connection = connectionFactory.newConnection();

        return connection;
    }

}
